<?php

class Application_Model_UserPasswordReset extends Application_Model_Disputeo
{
    protected $_userId;
    protected $_resetId;
    protected $_created;
    protected $_used = false;
    
    public function __construct(array $options = null)
    {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }
    
    public function setUserId($id)
    {
        $this->_userId = (int) $id;
        return $this;
    }

    public function getUserId()
    {
        return $this->_userId;
    }
    
    public function setResetId($text)
    {
        $this->_resetId = (string) $text;
        return $this;
    }

    public function getResetId()
    {
        return $this->_resetId;
    }
    
    public function setCreated($date)
    {
        $this->_created = (int) strtotime($date);
        return $this;
    }
    
    public function getCreated()
    {
        return $this->_created;
    }
    
    public function setUsed($bool)
    {
        $this->_used = (bool) $bool;
        return $this;
    }

    public function getUsed()
    {
        return $this->_used;
    }
    
    public function hasExpired()
    {
        $cutOff = time() - 1800;
        return ($this->_used && ($this->_created < $cutOff));
    }
    
    public function toArray()
    {
        return array(
            'user_id' => $this->_userId,
            'reset_id' => $this->_resetId,
            'created' => $this->_created,
            'used' => $this->_used
        );
    }
}